package cn.westv.scps.service.agent.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.westv.scps.dao.BaseDao;
import cn.westv.scps.domain.PublishAgentEntity;
import cn.westv.scps.service.agent.IAgentService;
import cn.westv.scps.utils.Page;

/**
 * 运营商管理
 * 
 * @author Administrator
 *
 */
@Service
@Transactional
public class AgentServiceImpl implements IAgentService {

	@Resource
	private BaseDao dao;

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<PublishAgentEntity> find(String hql, Class<PublishAgentEntity> publishAgentEntity, Object[] params) {

		return dao.find(hql, publishAgentEntity, params);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public PublishAgentEntity get(Class<PublishAgentEntity> publishAgentEntity, Serializable agentId) {

		return dao.get(publishAgentEntity, agentId);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public Page<PublishAgentEntity> findPage(String hql, Page<PublishAgentEntity> page,
			Class<PublishAgentEntity> publishAgentEntity, Object[] params) {

		return dao.findPage(hql, page, publishAgentEntity, params);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public String saveOrUpdate(PublishAgentEntity publishAgentEntity) {
		dao.saveOrUpdate(publishAgentEntity);
		return publishAgentEntity.getAgentId();
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public String save(PublishAgentEntity publishAgentEntity) {

		dao.save(publishAgentEntity);
		return publishAgentEntity.getAgentId();
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public String update(PublishAgentEntity publishAgentEntity) {

		dao.update(publishAgentEntity);
		return publishAgentEntity.getAgentId();
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public void saveOrUpdateAll(Collection<PublishAgentEntity> entitys) {
		dao.saveOrUpdateAll(entitys);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public String deleteById(Class<PublishAgentEntity> publishAgentEntity, Serializable agentId) {
		dao.deleteById(PublishAgentEntity.class, agentId);
		return null;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public void delete(Class<PublishAgentEntity> publishAgentEntity, Serializable[] ids) {
		dao.delete(PublishAgentEntity.class, ids);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<PublishAgentEntity> querySQL(String SQL, Object[] params,
			Class<PublishAgentEntity> publishAgentEntity) {

		return dao.querySQL(SQL, params, PublishAgentEntity.class);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public PublishAgentEntity findAgentByAccount(String account) {
		List<PublishAgentEntity> find = dao.find("from PublishAgentEntity where account like ?",
				PublishAgentEntity.class, new Object[] { "%" + account + "%" });
		if (find != null && find.size() > 0) {
			return find.get(0);
		}
		return null;
	}

}
